/**
 *
 */
package anysware.gwt.client.ui;

import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.ui.FlowPanel;

/**
 * TODO: doc me
 *
 * @author keke<keke@codehaus.org>
 * @revision $Revision: 103 $
 * @version
 */
public class SearchResultList extends ListView {
	private final JSONObject	results;

	public SearchResultList(final JSONObject results) {
		this.results = results;
		final FlowPanel outer = new FlowPanel();
		initWidget(outer);
		addStyleName("search");
	}

	@Override
	public void update(final JSONObject data) {
		final FlowPanel outer = (FlowPanel) getWidget();
		outer.clear();
		final JSONArray list = data.get("list").isArray();
		for (int i = 0; i < list.size(); i++) {
			final JSONObject result = list.get(i).isObject();
			DeferredCommand.addCommand(new Command() {
				public void execute() {
					final SearchResultBrief brief = new SearchResultBrief(
					        result);
					outer.add(brief);
				}
			});
		}

	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.google.gwt.user.client.ui.Widget#onLoad()
	 */
	@Override
	protected void onLoad() {
		super.onLoad();
		update(results);
	}

}
